/***************************************************************************
 *   Copyright (C) 2008 by BogDan Vatra   *
 *   taipan@licentia.eu   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef OPERATIUNICONTABILEWIDGET_H
#define OPERATIUNICONTABILEWIDGET_H

#include <kontamabilwindow.h>
/**
	@author BogDan Vatra <taipan@licentia.eu>
*/

class OperatiuniContabileWidget : public KontAMabilWindow
{
	Q_OBJECT
	Q_PROPERTY(int rows READ rows WRITE setRows)

public:

	struct Cell
	{
		int row;
		int col;
	};

	enum CellFlags
	{
		NoFlags=0, MouseOver=1, Selected=2
	};

public:
	OperatiuniContabileWidget(QWidget *parent = 0);
	~OperatiuniContabileWidget();
	Cell cellAt(const QPoint & point);
	QRect cellRect(Cell cell);
	QRect cellRect(int col, int row);
	Cell currentCell();
	void currentCell(int * col, int * row);
	void setCurrentCell(Cell cell);
	void setCurrentCell(int col, int row);
	int rows();
	void setRows(int nrows);

signals:
	void currentChanged(int col, int row);
	void editCell(int col, int row, const QRect & rect, const QString & text);
	void paintCell(int col, int row, QPainter & painter, const QRect & rect, int cellFlags);
	void deletePressed(int col, int row);

protected:
	void paintEvent(QPaintEvent *event);
	void mouseMoveEvent(QMouseEvent * event);
	void mousePressEvent(QMouseEvent * event);
	void mouseDoubleClickEvent(QMouseEvent * event);
	void keyPressEvent( QKeyEvent * event );

	void prepareCell(int col, int row, const QRect & rect, QPainter & painter);

private:
	int m_rows;
	int m_rowIndentation;
	int m_columnIndentation;
	int m_border;
	QPoint m_mousePos;
	Cell m_currentCell;
	Cell m_mouseOverCell;
	Cell m_oldMouseOverCell;
};

#endif
